﻿
#ifndef Ray_h
#define Ray_h

#pragma region License
/*
MIT License
Copyright Â© 2006 The Mono.Xna Team

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma endregion License


#include <Typedef.h>
#include <Defines.h>
#include <CSharpPropertyMethods.h>

#include <System/Object.h>
#include <System/Byte.h>
#include <System/Array.h>
#include <System/Nullable.h>
#include <System/Math.h>
#include <System/Generic/IEquatable.h>
#include <System/Collections/Generic/IEnumerable.h>
#include <System/ArgumentOutOfRangeException.h>
#include <System/ArgumentNullException.h>
#include <System/ArgumentException.h>

#include <Riccsson/Xna/Framework/Vector3.h>
#include <Riccsson/Xna/Framework/RMatrix.h>
#include <Riccsson/Xna/Framework/ContainmentType.h>
#include <Riccsson/Xna/Framework/PlaneIntersectionType.h>

namespace Riccsson
{
	namespace Xna
	{
		namespace Framework
		{
			// Forward declerations.
			struct BoundingBox;
			struct BoundingSphere;
			struct BoundingFrustum;
			struct Plane;

            struct Ray
				: public Riccsson::System::Generic::IEquatable<Ray>
            {
                #pragma region public: Fields

                public: Vector3 Direction;
                public: Vector3 Position;

                #pragma endregion

                #pragma region public: Constructors

                public: Ray(Vector3 position, Vector3 direction);

                #pragma endregion

                #pragma region public: Methods

			    public: override bool Equals(Riccsson::System::object* obj);

                public: bool Equals(Ray* other);

                public: override int GetHashCode();

                // adapted from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
                public: Riccsson::System::Nullable<float> Intersects(BoundingBox& box);
                        
                public: void Intersects(Plane ref plane, Riccsson::System::Nullable<float> out result);

                public: void Intersects(BoundingBox ref box, Riccsson::System::Nullable<float> out result);

                public: Riccsson::System::Nullable<float> Intersects(BoundingSphere& sphere);

				public: Riccsson::System::Nullable<float> Intersects(BoundingFrustum& frustum);

                public: Riccsson::System::Nullable<float> Intersects(Plane& plane);

                public: void Intersects(BoundingSphere ref sphere, Riccsson::System::Nullable<float> out result);

				public: override GC_PTR<Riccsson::System::string> ToString();
		
		        #pragma endregion
            };
            
            inline bool operator !=(Ray a, Ray b)
            {
                return !a.Equals(&b);
            }


            inline bool operator ==(Ray a, Ray b)
            {
                return a.Equals(&b);
            }
        }
	}
}

#endif